package com.fram.controller.admin;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fram.bean.sys.PageBean;
import com.fram.bean.sys.ResponseMsg;
import com.fram.common.canstant.ErrCode;
import com.fram.common.exception.ProException;
import com.fram.common.util.PublicMethod;
import com.fram.common.util.apiversion.ApiVersion;
import com.fram.entity.Checkversion;
import com.fram.service.admin.CheckversionService;

@RestController
@RequestMapping("/admin/{version}/auth/app/version")
public class CheckversionController {
	private static Logger LOG = LoggerFactory.getLogger(CheckversionController.class);

	@Autowired
	private CheckversionService checkversionService;
	/**列表**/
	@ApiVersion(1.0)
	@RequestMapping("list")
	private ResponseMsg list(@RequestBody PageBean<Checkversion> request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			msg.setData(checkversionService.list(request));
		} catch (ProException e) {
			LOG.error("-app版本列表出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-app版本列表异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
	/**增加**/
	@ApiVersion(1.0)
	@RequestMapping("add")
	private ResponseMsg add(@RequestBody Checkversion request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			checkversionService.add(request);
		} catch (ProException e) {
			LOG.error("-增加app版本出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-增加app版本异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
	/**修改**/
	@ApiVersion(1.0)
	@RequestMapping("update")
	private ResponseMsg update(@RequestBody Checkversion request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			checkversionService.update(request);
		} catch (ProException e) {
			LOG.error("-修改app版本出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-修改app版本出错->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
	
	@ApiVersion(1.0)
	@RequestMapping("details")
	private ResponseMsg details(Long id) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			msg.setData(checkversionService.details(id));
		} catch (ProException e) {
			LOG.error("-版本详情出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-版本详情异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
}
